package com.hdu.careerplan.controller;

import com.hdu.careerplan.pojo.dto.CityJobDTO;
import com.hdu.careerplan.pojo.dto.CityJobChoiceListDTO;
import com.hdu.careerplan.pojo.dto.TrendTimeDTO;
import com.hdu.careerplan.pojo.pythonData.SalaryData;
import com.hdu.careerplan.pojo.vo.TechListDataVO;
import com.hdu.careerplan.pojo.vo.Result;
import com.hdu.careerplan.pojo.vo.ResultData;
import com.hdu.careerplan.pojo.vo.TrendVO;
import com.hdu.careerplan.service.Impl.DataAnalysisServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/data_analysis")
public class DataAnalysisController {

    private final DataAnalysisServiceImpl dataAnalysisService;

    @Autowired
    public DataAnalysisController(DataAnalysisServiceImpl dataAnalysisService) {
        this.dataAnalysisService = dataAnalysisService;
    }


    //--以下为新的接口----------------------------
    // 初始用户在选择了一个城市和一个岗位的时候，返回对应的值
    @GetMapping("salary/initial_choice")
    public ResultData salaryInitialChoice(CityJobDTO cityJobDTO) {
        SalaryData salaryData = dataAnalysisService.salaryInitialChoice(cityJobDTO);
        if (salaryData == null) { // 空数据的返回情况
            return Result.noContent(null);
        }
        return Result.success(salaryData);
    }

    // 年薪比较，一个城市多个岗位
    @GetMapping("salary/compare_job")
    public ResultData compareSalaryByJob(CityJobChoiceListDTO cityJobChoiceListDTO) throws IOException, InterruptedException {
        List<SalaryData> salaryDataList = dataAnalysisService.compareSalary(0, cityJobChoiceListDTO);
        if (salaryDataList.isEmpty()) { // 空数据的返回情况
            return Result.noContent(null);
        }
        return Result.success(salaryDataList);
    }

    // 年薪比较，一个岗位多个城市
    @GetMapping("salary/compare_region")
    public ResultData compareSalaryByRegion(CityJobChoiceListDTO cityJobChoiceListDTO) throws IOException, InterruptedException {
        List<SalaryData> salaryDataList = dataAnalysisService.compareSalary(1, cityJobChoiceListDTO);
        if (salaryDataList.isEmpty()) { // 空数据的返回情况
            return Result.noContent(null);
        }
        return Result.success(salaryDataList);
    }

    // 初始用户在选择了一个城市和一个岗位的时候，返回对应的值
    @GetMapping("tech/initial_choice")
    public ResultData techInitialChoice(CityJobDTO cityJobDTO) throws IOException, InterruptedException {
        TechListDataVO techListDataVO = dataAnalysisService.techInitialChoice(cityJobDTO);
        if (techListDataVO == null) { // 空数据的返回情况
            return Result.noContent(null);
        }
        return Result.success(techListDataVO);
    }

    // top10相关技术占比，一个城市多个岗位
    @GetMapping("tech/compare_job")
    public ResultData companyTechByJob(CityJobChoiceListDTO cityJobChoiceListDTO) throws IOException, InterruptedException {
        List<TechListDataVO> techListDataListVO = dataAnalysisService.compareTech(0, cityJobChoiceListDTO);
        if (techListDataListVO.isEmpty()) { // 空数据的返回情况
            return Result.noContent(null);
        }
        return Result.success(techListDataListVO);
    }

    // top10相关技术占比，一个岗位多个城市
    @GetMapping("tech/compare_region")
    public ResultData companyTechByJobRegion(CityJobChoiceListDTO cityJobChoiceListDTO) throws IOException, InterruptedException {
        List<TechListDataVO> techListDataListVO = dataAnalysisService.compareTech(1, cityJobChoiceListDTO);
        if (techListDataListVO.isEmpty()) { // 空数据的返回情况
            return Result.noContent(null);
        }
        return Result.success(techListDataListVO);
    }
    @GetMapping("/trend")
    public ResultData getAndGroupTrendDate(TrendTimeDTO trendTimeDTO) {
        List<TrendVO> andGroupTrendDate = dataAnalysisService.getAndGroupTrendDate(trendTimeDTO);
        if (andGroupTrendDate == null) {
            return Result.noContent(null);
        }
        return Result.success(andGroupTrendDate);
    }

}
